package com.c201801020208.ybl.User.Activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.c201801020208.ybl.Adapters.jianliAdapter;
import com.c201801020208.ybl.R;
import com.c201801020208.ybl.Tool.DensityUtil;
import com.google.android.material.appbar.CollapsingToolbarLayout;


import java.util.ArrayList;
import java.util.List;

public class homeActivity extends AppCompatActivity {


    private RelativeLayout toolsRe, backRe, overRe;
    private ViewPager viewPager;
    private View view1, view2;
    private List<View> viewList;
    private PagerAdapter pagerAdapter;
    public static Handler mHandler;
    TextView textView;

    private RecyclerView listView;
    private LinearLayoutManager layoutManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.personal_home_page);
        textView = findViewById(R.id.name);
        textView.setText(getIntent().getStringExtra("name"));
        toolsRe = (RelativeLayout) findViewById(R.id.toolsre);//最上面
        backRe = (RelativeLayout) findViewById(R.id.backre);//上半区
        overRe = (RelativeLayout) findViewById(R.id.over_re);//整个界面

        viewPager = (ViewPager) findViewById(R.id.viewpager);//下半区

        LayoutInflater lf = getLayoutInflater().from(this);
        view1 = lf.inflate(R.layout.layout1, null);//个人信息
        view2 = lf.inflate(R.layout.layout2, null);//详细信息
        viewList = new ArrayList<View>();
        viewList.add(view1);
        viewList.add(view2);


        listView = (RecyclerView) view1.findViewById(R.id.list);
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < 50; ++i) {
            list.add(" 简历 " + i);
        }
        listView.setAdapter(new jianliAdapter(this));
        layoutManager = new LinearLayoutManager(this);
        listView.setLayoutManager(layoutManager);


        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                float alpha = ((float) msg.what) / 100f;
                Log.e("alpha", msg.what + ":" + alpha);
                overRe.setAlpha(alpha);

                if (msg.what == 0) {
                    backRe.setVisibility(View.INVISIBLE);
                    toolsRe.setVisibility(View.VISIBLE);
                } else {
                    backRe.setVisibility(View.VISIBLE);
                    toolsRe.setVisibility(View.INVISIBLE);

                }


            }
        };


        pagerAdapter = new PagerAdapter() {//滑动效果

            @Override
            public boolean isViewFromObject(View arg0, Object arg1) {

                return arg0 == arg1;
            }

            @Override
            public int getCount() {

                return viewList.size();
            }

            @Override
            public void destroyItem(ViewGroup container, int position,
                                    Object object) {
                container.removeView(viewList.get(position));

            }

            @Override
            public int getItemPosition(Object object) {

                return super.getItemPosition(object);
            }


            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                container.addView(viewList.get(position));

                return viewList.get(position);
            }

        };


        viewPager.setAdapter(pagerAdapter);
        backRe.setPadding(0, 0, 0, DensityUtil.getZhuangtai(this));


        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);//个人中心和详细信息
        setSupportActionBar(toolbar);

        CollapsingToolbarLayout collapsingToolbar =
                (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);//上半区折叠

        //collapsingToolbar.setBackgroundResource(R.drawable.main);

    }

    public void dodo2(View v) {
        finish();
    }

    public void dodo(View v) {


        viewPager.setCurrentItem(0);


    }

    public void dodo1(View v) {


        viewPager.setCurrentItem(1);

    }

    class StringAdapter extends RecyclerView.Adapter<ViewHolder> {


        private List<String> list;
        private LayoutInflater inflater;

        StringAdapter(List<String> list) {
            this.list = list;
            inflater = LayoutInflater.from(homeActivity.this);
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position, List<Object> payloads) {
            super.onBindViewHolder(holder, position, payloads);
        }

        @Override
        public long getItemId(int position) {
            return super.getItemId(position);
        }

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = inflater.inflate(R.layout.item, null, false);

            return new ViewHolder(view);
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position) {
            holder.tv.setText(list.get(position));

        }

        @Override
        public int getItemCount() {
            return list.size();
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tv;

        public ViewHolder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.tv);
        }
    }
}